package 数组.除自身以外数组的乘积238;

import utils.Utils;

public class Solution {
    public static int[] productExceptSelf(int[] nums) {
        int[] res = new int[nums.length];
        res[0] = 1;
        for(int i=1;i<nums.length;i++){
            res[i] = nums[i-1]*res[i-1];
        }

        int right = 1;
        for(int i=nums.length-1;i >=0;i--){
            res[i] = res[i] * right;
            right *= nums[i];
        }

        return res;

    }

    public static void main(String[] args) {
        int[] nums = {-1,1,0,-3,3};
        Utils.printIntArr(productExceptSelf(nums));
    }
}
